package com.cdxy.dmr.repository;

import com.cdxy.dmr.dataObject.AxUserDO;
import com.cdxy.dmr.mapper.AxUserMapper;
import com.cdxy.model.dto.base.mybatis.BaseRepository;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author autoGenCode
 * @since 2020-03-05
 */
@Repository
@CacheConfig(cacheNames = "ax_user")
public class AxUserRepository extends BaseRepository<AxUserMapper, AxUserDO> {

    /**
     * 通过手机号查找用户
     *
     * @param mobile
     * @return
     */
    @Cacheable(key = "#mobile", unless = "#result == null ")
    public AxUserDO getByMobile(String mobile) {
        return this.baseMapper.selectOne(this.queryWrapper()
                .eq(AxUserDO::getMobile, mobile));
    }

    /**
     * 通过邮箱查找用户
     *
     * @param email
     * @return
     */
    @Cacheable(key = "#email", unless = "#result == null ")
    public AxUserDO getByEmail(String email) {
        return this.baseMapper.selectOne(this.queryWrapper()
                .eq(AxUserDO::getMobile, email));
    }

}
